<?php

/**
 * Created by PhpStorm.
 * User: thorjiang
 * Date: 2018/5/9
 * Time: 17:09
 */
namespace App\Http\Middleware;

use Closure;

class AdminAuth
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(!$this->checkAdmin($request))
        {
            return getErrorResponse(CODE_ADMIN_ACCOUNT_NEED_LOGIN, '尚未登录');
        }

        return $next($request);
    }

    protected function checkAdmin($request)
    {
        $userId = $request->session()->get('user_id');
        if (empty($userId)) {
            return false;
        }

        return true;
    }
}
